@isTest
private class CaseHandlerTest {
    static testMethod void testMethod1() {

        Id ldcProfile = [Select Id From Profile Where Name like  '%工程%' limit 1].Id;

        User ldc1 = new User( Alias= 'samLdc7', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = 'samLdc', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(产品培训部)',
                         Timezonesidkey = 'America/Los_Angeles',
                         IsTeamLeader__c = false,
                         IsExpert__c =  true,
                         Area__c = '四川一区',
                         EmployeeNumber = '123456',
                           CompanyName = 'Y-MKSY',
                         FederationIdentifier = 'test1',
                         Username = 'ldc@test.com.maike' );
        insert ldc1;

        User ldc2 = new User( Alias = 'samLdc7', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = 'samLdc', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c = '客户服务中心(产品培训部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         IsTeamLeader__c = true,
                         Area__c = '四川一区',
                         ProductLine__c = '生化',
                         EmployeeNumber = '123456',
                           CompanyName = 'Y-MKSY',
                         FederationIdentifier = 'test2',
                         Username = 'ldc2@test.com.maike' );
        insert ldc2;

        User ldc3 = new User( Alias = 'samLdc7', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = 'samLdc', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c ='总经办',
                         Timezonesidkey = 'America/Los_Angeles', 
                         IsTeamLeader__c = true,
                         Area__c = '四川一区',
                         ProductLine__c = '生化',
                         EmployeeNumber = '123456',
                            CompanyName = 'Y-MKSY',
                         FederationIdentifier = 'test3',
                         Username = 'ldc3@test.com.maike' );
        insert ldc3;

        Account acc = TestUtils.createAccount();
        insert acc;

        Case ca = new Case();
        ca.AccountId = acc.Id;
        insert ca;

        // 升级给专家组
        ca.Professional__c = ldc1.Id;
        update ca;

        // 分配给组长
        try {
            ca.ProductLine__c = 'xxxxx';
            ca.CaseDepartment__c = '产陪';
            ca.District__c = '四川西藏一部';
            update ca;
        } catch (Exception e) {
        	// 找不到
        }

        ca.ProductLine__c = '生化';
        ca.CaseDepartment__c = '客户服务中心(产品培训部)';
        ca.District__c = '四川一区';
        update ca;

        ca = [select User__c from Case where Id = :ca.Id];
      //  System.assertEquals(ldc2.Id, ca.User__c);

        // 设定工程师
        ca.Engineer__c = ldc3.Id;
        update ca;

        // 个案关闭
        ca.Status = '关闭';
        update ca;
    }
}